//
//  IGArtistVC.m
//  jingdongfang
//
//  Created by MTiMac02 on 2018/5/7.
//  Copyright © 2018年 BOE-SBG-CTO. All rights reserved.
//

#import "IGMyArtistVC.h"
#import "NoneArtistView.h"
#import "MyGArtCell.h"
#import "IGMyFocusMemberApi.h"
#import "IntroViewController.h"

@interface IGMyArtistVC ()
{
    NSString *uid;
    NSString *pageNum;//页数，从1开始
}
@property(strong,nonatomic)NoneArtistView *noArtistView;
@property (nonatomic, strong)IGMyFocusMemberApi *myMemberApi;
@property (nonatomic, strong)NSMutableArray *dataArr;
@property (nonatomic, strong)NSMutableArray *recDataArr;
@end

@implementation IGMyArtistVC
#pragma mark - 懒加载
-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr=[NSMutableArray array];
    }
    return _dataArr;
}
-(NSMutableArray *)recDataArr{
    if (!_recDataArr) {
        _recDataArr=[NSMutableArray array];
    }
    return _recDataArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor mainBackgroundColor];
    [self.tableView setTableFooterView:[[UIView alloc]initWithFrame:CGRectZero]];
    [self.tableView addSubview:self.noArtistView];
    [self.tableView registerNib:[UINib nibWithNibName:@"MyGArtCell" bundle:nil] forCellReuseIdentifier:@"MyGArtCell"];
    self.myMemberApi=[IGMyFocusMemberApi new];
    [self firstPage];
}
-(void)firstPage{
    pageNum= @"1";
    uid=[IGUser getUid];
    [self requestData];
}
-(void)requestData{
    self.myMemberApi.pageNum=pageNum;
    self.myMemberApi.uid=uid;
    @KWeakObj(self)
    [self.myMemberApi startWithDecodeClass:[IGMyFocusMemberResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
            IGMyFocusMemberResp *resp=responseObject;
            IGMyFocusMemberModel *model=resp.data;
            if ([pageNum isEqualToString:@"1"])
            {
                _dataArr= [NSMutableArray arrayWithArray:model.focusMemberList];;
               _recDataArr = [NSMutableArray arrayWithArray:model.recMemberList];
            }
            else
            {
                [_dataArr addObjectsFromArray:model.focusMemberList];
                [_recDataArr addObjectsFromArray:model.recMemberList];
            }
            if (self.dataArr.count==0) {
                self.noArtistView.hidden=NO;
            }else{
                self.noArtistView.hidden=YES;
            }
            [selfWeak.tableView reloadData];
        }
    }];
}
#pragma mark 懒加载
-(NoneArtistView *)noArtistView{
    if (!_noArtistView) {
        _noArtistView=[[NoneArtistView alloc]initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, KSCREENHEIGHT - NavigationMagin-44)];
    }
    return _noArtistView;
}
- (void)scrollToTOP
{
    [self.tableView setContentOffset:CGPointMake(0, 0) animated:YES];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _dataArr.count?_dataArr.count:0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     MyGArtCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MyGArtCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[MyGArtCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyGArtCell"];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleDefault;
    cell.data=_dataArr[indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    IntroViewController *vc=[[IntroViewController alloc]init];
    MyFocusMemberModel *info=_dataArr[indexPath.row];
    vc.u_id=info.aid;
    [UIViewController ig_pushViewController:vc animated:YES];
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 71;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 5;
    }
    return 0.01f;
    
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *head=[[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, 5)];
    return head;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
